package org.west.sky.frame.activiti.study.chapter14.demo0102;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.Expression;
import org.activiti.engine.delegate.JavaDelegate;

/**
 * author: chz
 * date: 2025/3/20
 * description:
 */
public class CalculationStringFieldInjectedJavaDelegate implements JavaDelegate {

    private Expression unitPrice;

    private Expression quantity;

    private Expression discount;

    private Expression description;

    @Override
    public void execute(DelegateExecution execution) {
        System.out.println("====开始计算");
        Object unitPriceValue = unitPrice.getValue(execution);
        Object quantityValue = quantity.getValue(execution);
        Object discountValue = discount.getValue(execution);
        Object descriptionValue = description.getValue(execution);
        System.out.println("====单价：" + unitPriceValue + "，数量：" + quantityValue + "，折扣：" + discountValue + "，描述：" + descriptionValue);
        double totalMoney = Double.parseDouble(unitPriceValue.toString()) * Integer.parseInt(quantityValue.toString()) * Double.parseDouble(discountValue.toString());
        System.out.println("====计算结束，总金额：" + totalMoney);
        execution.setVariable("totalMoney", totalMoney);
    }

    public Expression getUnitPrice() {
        return unitPrice;
    }

    public Expression getQuantity() {
        return quantity;
    }

    public Expression getDiscount() {
        return discount;
    }

    public Expression getDescription() {
        return description;
    }
}
